var app = getApp();
var util = require('../../../utils/util.js');

Page({
    data: {
        imgUrl:app.globalData.imgUrl,
        systemInfo:{},
        padBtm:"25",
        detId:"",
        serveDet:"",
        bannerList: "",
        serveText: "",
        scrollFlag:true
    },
    onLoad: function (e) {
        var that = this;
        wx.getSystemInfo({
            success:function(res){
              that.setData({
                systemInfo:res,
                navH: app.globalData.navHeight
              })
              if(res.model == "iPhone X"){
                    that.setData({
                        padBtm:"50",
                    })
              }
            }
        });
        that.setData({
            detId:e.id,
        });
        that.getImg();
        that.getServeDet();
    },
    onShareAppMessage() {
        var that = this;
        return {
          title: '在海花岛这样订房也不错，快看快约！',
          //path: 'pages/activity/index/activity-index?id='+that.data.detId
          //path: 'pages/index/index?type=activity&id=' + that.data.detId
          path: 'pages/index/index?url=/pages/activity/index/activity-index&id=' + that.data.detId
        }
    },
    getImg:function(){
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/index/bannerList",
            data: {
                position: "activicy"
            },
            header: {  
                'content-type': 'application/json' 
            },
            method: "GET",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var imgData = res.data.data;
                    that.setData({
                        imgList: imgData
                    })
                }
            },
            
        });
    },
    getServeDet:function(){
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/index/goodsDetails",
            data: {
                id: that.data.detId
            },
            header: {  
                'content-type': 'application/json' 
            },
            method: "GET",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var serveData = res.data.data;
                    var serveBanner = serveData.pics.split(',');
                    var serveBody=serveData.body;
                    var serveTextCode=util.baseDecode(serveBody);  //base64解码
                    that.setData({
                        serveDet: serveData,
                        bannerList: serveBanner,
                        serveText: serveTextCode,
                    })
                }
            },
            
        });
    },
    onPageScroll:function(e){
        var that = this;
        if(e.scrollTop>=140){
            that.setData({
                scrollFlag: false
            });
        }else{
            that.setData({
                scrollFlag: true
            });
        }
    },
    navBack: function () {
        // wx.navigateBack({
        //   delta: 1
        // })
        //console.log(1111);
      wx.reLaunch({
        url: '/pages/index/index'
      })
      
    },
})
